package serverside;

import javax.swing.*;

import java.awt.Toolkit;
import java.awt.*;
import java.awt.event.*;

public class JavaApplication1 extends JFrame {
    private JFrame frame;
    public int check = 0;
    public Jp jp = new Jp();
    public CheckATMs checkATMs = new CheckATMs();
    //public ATMConfig ATMconfig = new ATMConfig();
    private JButton login;
    //private JButton config;
    private JButton ATMs;
    private JButton logout;
    private JButton increment;
    public  int inc = 0;
    private JLabel label = new JLabel("");
    private JLabel l = new JLabel(new ImageIcon(getClass().getResource("b11.jpg")),JLabel.LEFT);
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
    
    public JavaApplication1(){
        super("Shoubrah ATM");
        //frame.setDefaultLookAndFeelDecorated(true);
        

        
        size.width = 500;
        size.height = 300;
        frame = new JFrame("ATM");
        //-----------------------------full
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        frame.setUndecorated(true);
        //----------------------------------
        frame.setResizable(false);
        frame.setSize(1280, 750);
        frame.setLocationRelativeTo(null);
        frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
        frame.setVisible(true);
        frame.setMinimumSize(size);
        
        
        addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {
                        System.exit(WIDTH);
                    }
                });
        
        /*frame.addComponentListener( new ComponentAdapter() {
            @Override
            public void componentResized( ComponentEvent e ) {
                login.setBounds(frame.getSize().width/2, frame.getSize().height/4 ,100 , 25);
            }
        } );*/
        
        
        label.setBounds(0, 0, 300, 40);
        Font font = new Font("Arial", Font.BOLD, 12);
        label.setFont(font);
        label.setForeground(Color.white);
        
        l.setBounds(0,0,frame.getSize().width,frame.getSize().height);
        //l.setToolTipText( "Welcome to Shoubrah ATM , sir!" );
        l.setEnabled(true);
        frame.setLayout(null);
        login = new JButton("Login");
        login.setBounds(600, 350 , 100 , 25);
        //config = new JButton("ATM Configuration");
        //config.setBounds(580, 390 , 140 , 25);
        logout = new JButton("Logout");
        logout.setVisible(false);
        logout.setBounds(600, 350 , 100 , 25);
        ATMs = new JButton("Check ATMs");
        ATMs.setBounds(590, 385 , 120 , 25);
        ATMs.setVisible(false);
        
        increment = new JButton("Increment");
        increment.setBounds(600, 450 , 100 , 25);
        increment.addMouseListener(new MouseAdapter(){
            public void mousePressed(MouseEvent e) {
              inc = 1;
            }
        });
        
        checkATMs.setBounds(360,280,900,400);
        checkATMs.setEnabled( true );
        //ATMconfig.setBounds(360,280,900,400);
        //ATMconfig.setEnabled( true );
        jp.setBounds(360,280,900,400);
        jp.setEnabled( true );
        initialization();
        
        l.updateUI();
        login.addMouseListener(new MouseAdapter(){
            String s;
            public void mousePressed(MouseEvent e) {
                login.setVisible(false);
                //config.setVisible(false);
                jp.setVisible(true);
                l.updateUI();
                /*
                frame.addComponentListener( new ComponentAdapter() {
            @Override
            public void componentResized( ComponentEvent e ) {
                login.setBounds(frame.getSize().width/2, frame.getSize().height/3 ,100 , 25);
            }
        } );*/
            }
        });
        logout.addMouseListener(new MouseAdapter(){
            public void mousePressed(MouseEvent e) {
                jp.b = 1;
                jp.u = 0;
                l.updateUI();
            }
        });
        
        ATMs.addMouseListener(new MouseAdapter(){
            public void mousePressed(MouseEvent e) {
                jp.u = 0;
                check = 1;
                l.updateUI();
            }
        });/*
        config.addMouseListener(new MouseAdapter(){
            public void mousePressed(MouseEvent e) {
                jp.b = 0 ;
                jp.u = 0 ;
                check = 2;
                //ATMconfig.changID(checkATMs.ind + 1);
            }
        });*/
        //frame.addContainerListener(ContainerAdapter);
    }
    
    
    public void initialization(){
        frame.getContentPane().add(login);
        //frame.getContentPane().add(increment);
        //frame.getContentPane().add(config);
        frame.getContentPane().add(logout);
        frame.getContentPane().add(ATMs);
        frame.getContentPane().add(label);
        //frame.getContentPane().add(ATMconfig);
        //ATMconfig.setVisible(false);
        frame.getContentPane().add(jp);
        jp.setVisible(false);
        frame.getContentPane().add(checkATMs);
        checkATMs.setVisible(false);
        frame.getContentPane().add(l);
    }
    public void visible(){
        login.setVisible(true);
        increment.setVisible(true);
        //config.setVisible(true);
        l.updateUI();
    }
    
    public void clear(){
        login.setVisible(false);
        increment.setVisible(false);
        //config.setVisible(false);
        l.updateUI();
    }
    
    public void print(String s , boolean b){
        if(b == true){
            label.setText("Mr. "+s);
        }
        else{
            label.setText(s);
        }
    }
    
    public void DisplayButton(){
        if(jp.u == 1){
            logout.setVisible(true);
            ATMs.setVisible(true);
        }
        else{
            logout.setVisible(false);
            ATMs.setVisible(false);
        }
    }
    
    public void update(){
        l.updateUI();
    }
    
}
